//
//  RigisterVC.swift
//  DollarBuy
//
//  Created by 郑东喜 on 2016/11/7.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class RigisterVC: MeBaseViewController {
    
    
  
    //用户名
    @IBOutlet weak var tfNum: UITextField!
    
    //密码
    @IBOutlet weak var tfPass: UITextField!
    
    //验证码
    @IBOutlet weak var tfAuto: UITextField!

    //确认密码
    @IBOutlet weak var tfConfirmPass: UITextField!
    
    //同意协议文本
    @IBOutlet weak var agreeLabel: UILabel!
    
    //同意图片显示是否
    @IBOutlet weak var isAgrreIimgShow: UIImageView!
    
    //同意协议
    @IBAction func confirmAgree(_ sender: UIButton) {

        sender.isSelected = !localSave.bool(forKey: agreeLaw)

        if sender.isSelected {
            self.isAgrreIimgShow.isHidden = true
            localSave.set(sender.isSelected, forKey: agreeLaw)
        } else {
            self.isAgrreIimgShow.isHidden = false
            localSave.set(sender.isSelected, forKey: agreeLaw)
        }
        localSave.synchronize()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        isAgrreIimgShow.isHidden = localSave.bool(forKey: agreeLaw)
        
        print(localSave.bool(forKey: agreeLaw))
    }
    
    //发送验证码
    @IBAction func sendAuto(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("发送验证码")))")
        
        self.sendRigisterMsg(tfNum: self.tfNum)
//        
//        //检查验证码是否为空
//        if self.tfNum.text?.characters.count == 0 {
//            MBManager.showBriefAlert(tfNumIsNull)
//        } else if Encryption.checkTelNumber(self.tfNum.text) == false {
//            
//            MBManager.showBriefAlert(tfNumNotCor)
//        } else if Encryption.checkTelNumber(self.tfNum.text) == true {
//            
//            
//            let params = ["type":1,
//                          "phone":self.tfNum.text!] as [String : Any]
//            print(params)
//            
//            MBManager.showPermanentAlert("发送中...")
//            manager.post(sendMsgUrl, parameters: params, success: { (task, response) in
//                
//                let json = JSON(response:response!)
//                print("\((#file as NSString).lastPathComponent):(\(#line))")
//                print(json)
//                
//                if json["resultmsg"] == "手机号已被注册" {
//                    MBManager.hideAlert()
//                    MBManager.showBriefAlert(numUsed)
//                    return
//                } else if json["resultmsg"] == "成功" {
//                    MBManager.hideAlert()
//                    MBManager.showBriefAlert(msgSended)
//                } else if json["resultmsg"] == "触发业务流控" {
//                    MBManager.hideAlert()
//                    MBManager.showBriefAlert(msgSendFail)
//                }
//                
//            }) { (task, error) in
//                print("\((#file as NSString).lastPathComponent):(\(#line))")
//                print(error)
//            }
//  
//        }
    }
    

    //注册
    @IBAction func rigisterSEL(_ sender: UIButton) {
        
        self.rigister(tfNum: self.tfNum, tfAuto: self.tfAuto, tfPass: self.tfPass, tfconfirmPass: self.tfConfirmPass)

    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.agreeLabel.attributedText = CoTool.shareInstance.labelWithUnderLine(text: "同意注册协议")
        self.agreeLabel.isUserInteractionEnabled = true
        
        let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(RigisterVC.clickLabel))
        self.agreeLabel.addGestureRecognizer(tapGes)

        // Do any additional setup after loading the view.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}

// MARK:- 同意协议
extension RigisterVC {
    func clickLabel() {
        print("点击label")
    }
}

//记录同意图片的显示状态
extension RigisterVC {
    
}
